package main.userInterface.critterui.critterviewer;


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class CritterTestFrame extends JFrame {

    private Drawing drawing ;
    CritterCanvas bar;
    JLabel loclab;
    private JButton save;
    private JButton random;

    public CritterTestFrame(){
		super("WALLACE'S ISLAND Critters");
        setSize(470,360);
        setResizable(true);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        this.setLayout(new BorderLayout());

        drawing = new Drawing();
        bar = new CritterCanvas();
        bar.putDrawing(drawing);

        bar.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent mouseEvent) {
                drawing.addToCurrent( new Point(mouseEvent.getX(), mouseEvent.getY() ) );
                bar.repaint();
            }

            public void mousePressed(MouseEvent mouseEvent) {}
            public void mouseReleased(MouseEvent mouseEvent) {}
            public void mouseEntered(MouseEvent mouseEvent) {}
            public void mouseExited(MouseEvent mouseEvent) {}
        });

        loclab = new JLabel("x : Y");

        bar.addMouseMotionListener(new MouseMotionListener() {
            @Override
            public void mouseDragged(MouseEvent mouseEvent) {
                loclab.setText("X "+mouseEvent.getX()+ " : Y "+mouseEvent.getY());
            }

            @Override
            public void mouseMoved(MouseEvent mouseEvent) {
                loclab.setText("X "+mouseEvent.getX()+ " : Y "+mouseEvent.getY());
            }
        });

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());

        save = new JButton("Save");
        save.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                drawing.save();
            }
        });

        random = new JButton("Random");
        random.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                bar.newCritter();
            }
        });

        JPanel buttons = new JPanel(new BorderLayout());
        buttons.add(save, BorderLayout.EAST) ;
        buttons.add(random , BorderLayout.WEST);

        panel.add(buttons , BorderLayout.EAST);
        panel.add(loclab , BorderLayout.WEST);


        this.add(bar , BorderLayout.CENTER);
        this.add(panel , BorderLayout.PAGE_END);
        setVisible(true);
        toFront();
	}


    public static void main(String args[]) throws Exception {
    	//System.out.println("FOOFOO");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        CritterTestFrame thegui = new CritterTestFrame();
    }
	
	
}
